let db = require("../db/index");

// 物业通知列表查询
exports.noticelists = (req, res) => {
    var sql =
        `SELECT * FROM propricenotice`;
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }else{
            res.send(data);
        }
    });
};
//添加通知
exports.noticeinsert= (req, res) => {
    var sql =
        `INSERT INTO propricenotice(NotificationTitle,Belongingcommunity,Noticetype,publisher,state,del,opertes,examine,view,Acceptancescope,Remindermethod,Noticecount)VALUES('${req.body.NotificationTitle}','${req.body.Belongingcommunity}','${req.body.Noticetype}','${req.body.publisher}','待审核',' 编辑',' 删除',' 审核',' 查看',' ${req.body.radio=='1'?'全体楼宇':'指定楼宇'}','${req.body.radios=='1'?'系统消息':'短信通知'}','${req.body.Noticecount}')`;
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }else{
            res.send({
                state:200
            })
        }
    });
};

// 编辑通知
exports.noticeupdate= (req, res) => {
    var sql = `UPDATE propricenotice SET NotificationTitle='${req.body.NotificationTitle}',Belongingcommunity='${req.body.Belongingcommunity}',Noticetype='${req.body.Noticetype}',publisher='${req.body.publisher}',Acceptancescope=' ${req.body.radio=='1'?'全体楼宇':'指定楼宇'}',Remindermethod='${req.body.radios=='1'?'系统消息':'短信通知'}',Noticecount='${req.body.Noticecount}' WHERE notice_id=${req.body.id}`;
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }else{
            res.send({
                state:200
            })
        }
    });
};
// 删除通知
exports.noticedelete = (req, res) => {
    var sql =
        `DELETE FROM propricenotice WHERE notice_id=${req.body.id}`;
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }else{
            var sql =
                `SELECT * FROM propricenotice`;
            db.query(sql, [], (err, data) => {
                if (err) {
                    console.log("出错了", err);
                    return res.send("错误" + err.message);
                }else{
                    res.send(data);
                }
            });
        }
    });
};